CC = gcc
ASSEMBLER = nasm
DEBUG_ASSEMBLER = -g
DEBUG_C = -ggdb3
RELEASE_ASSEMBLER =
RELEASE_C = -O2 -Wall -s

# Linux develop targets

only: all
	make clean_obj

all: clean config_linux
	$(ASSEMBLER) $(DEBUG_ASSEMBLER) -f elf haffman_main.asm
	$(CC) $(DEBUG_C) -c support_func.c -o support_func.o
	$(CC) $(DEBUG_C) haffman_main.o support_func.o main.c -o haffman_console

clean: clean_obj
	rm -f haffman_console

clean_obj:
	rm -f config.asm *.o

#Linux release targets

release_linux: config_linux
	rm -f ../build/haffman_main.o ../build/support_func.o ../bin/haffman_console
	$(ASSEMBLER) $(RELEASE_ASSEMBLER) -f elf haffman_main.asm -o ../build/haffman_main.o
	$(CC) $(RELEASE_C) -c support_func.c -o ../build/support_func.o
	$(CC) $(RELEASE_C) ../build/haffman_main.o ../build/support_func.o main.c -o ../bin/haffman_console

# Windows release targets

release_windows: config_windows
	del ..\build\haffman_main.o ..\build\support_func.o ..\bin\haffman_console.exe
	$(ASSEMBLER) $(RELEASE_ASSEMBLER) -f win32 haffman_main.asm -o ..\build\haffman_main.o
	$(CC) $(RELEASE_C) -c support_func.c -o ..\build\support_func.o
	$(CC) $(RELEASE_C) ..\build\haffman_main.o ..\build\support_func.o main.c -o ..\bin\haffman_console

# Config targets

config_linux:
	echo '%define LINUX' > config.asm

config_windows:
	echo %%define WINDOWS > config.asm

